using System;
using System.Collections.Generic;
using System.Text;

namespace Weazel.Microblaze.Simulator.Components.Microblaze.Instructions
{
    /// <summary>
    /// Logical OR with Immediate
    /// </summary>
    public class Ori : Instruction
    {
        public override int CycleCount
        {
            get { return 1; }
        }

        public Ori()
            : base("ori")
        {
        }

        /// <summary>
        /// The contents of register rA are ORed with the extended IMM field, 
        /// sign-extended to 32 bits; the result is placed into register rD.
        /// </summary>    
        public override void Execute(MicroblazeComponent MicroblazeComponent)
        {
            uint sa = MicroblazeComponent.ReadRegister(SourceRegisterA);
            uint imm = (uint)GetImmediateValue(MicroblazeComponent);
            uint rd = sa | imm;

            MicroblazeComponent.WriteRegister(DestinationRegister, rd, Address);
        }


        public override string ToString()
        {
            return String.Format("ori r{0}, r{1}, {2}",
                DestinationRegister,
                SourceRegisterA,
                ImmediateValue
            );
        }
    }
}
